package com.kailong.controller.sys;

import com.kailong.annotation.NoLogin;
import com.kailong.dto.sys.DeptTreeDTO;
import com.kailong.entity.ResponsePageEntity;
import com.kailong.entity.sys.DeptConditionEntity;
import com.kailong.entity.sys.DeptEntity;
import com.kailong.service.sys.DeptService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * created by kailong on 2025/9/3
 */
@RestController
@RequestMapping("/v1/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Operation(summary = "根据条件查询部门列表", description = "根据条件查询部门列表")
    @RequestMapping("/searchByPage")
    public ResponsePageEntity<DeptTreeDTO> searchByPage(@RequestBody DeptConditionEntity deptConditionEntity) {
        return deptService.searchByPage(deptConditionEntity);
    }
    /**
     * 删除部门
     *
     * @param ids 部门ID
     * @return 影响行数
     */
    @Operation(summary = "删除部门", description = "删除部门")
    @PostMapping("/deleteByIds")
    public int deleteByIds(@RequestBody @NotNull List<Long> ids) {
        return deptService.deleteByIds(ids);
    }


    /**
     * 导出部门数据
     *
     * @return 影响行数
     */
    @NoLogin
    @Operation(summary = "导出部门数据", description = "导出部门数据")
    @PostMapping("/export")
    public void export(@RequestBody  DeptConditionEntity deptConditionEntity) throws IOException {

    }
    /**
     * 新增部门
     *
     * @param deptEntity 部门实体
     * @return 影响行数
     */
    @Operation(summary = "新增部门", description = "新增部门")
    @PostMapping("/insert")
    public int insert(@RequestBody DeptEntity deptEntity) {
        return deptService.insert(deptEntity);
    }
    /**
     * 修改部门
     *
     * @param deptEntity 部门实体
     * @return 影响行数
     */
    @Operation(summary = "修改部门", description = "修改部门")
    @PostMapping("/update")
    public int update(@RequestBody DeptEntity deptEntity) {
        return deptService.update(deptEntity);
    }

}
